#更改xml中某一类
import os
input_dir='/home/xys/CloundShiProjects/motorbicyle_detect/motor_obj_det_data/test/0112err/0112_part/xml/'
shu=0
new_name1 = 'mtc_weideng'
# new_name2 = 'e_fuzhuzhidong'
# new_name3 = 'e_abs'
# new_name4 = 'e_asr'
# new_name5='d'

import xml.etree.ElementTree as ET
for filename in os.listdir(input_dir):
    file_path = os.path.join(input_dir, filename)
    dom = ET.parse(file_path)
    root = dom.getroot()
    for obj in root.iter('object'):  # 获取object节点中的name子节点
        if obj.find('name').text == 'mtc-weideng':
            obj.find('name').text = new_name1
            shu=shu+1
            #print("change %s to %s." % (yuan_name, new_name1))
        # elif obj.find('name').text == 'fuzhuzhidong':
        #     obj.find('name').text = new_name2
        #     shu = shu + 1
        # elif obj.find('name').text == 'abs':
        #     obj.find('name').text = new_name3
        #     shu = shu + 1
        # elif obj.find('name').text == 'asr':
        #     obj.find('name').text = new_name4
        #     shu = shu + 1
        # elif obj.find('name').text == 'fanmian':
        #     obj.find('name').text = new_name4
        #     shu = shu + 1

  # 保存到指定文件
    dom.write(file_path, xml_declaration=True)
print("有%d个文件被成功修改。" % shu)
